package com.ruoyi.business.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.UserExam;
import com.ruoyi.business.domain.bo.UserExamBo;
import com.ruoyi.business.domain.vo.UserExamVo;
import com.ruoyi.business.mapper.UserExamMapper;
import com.ruoyi.business.service.IUserExamService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 * @author 最爱喝兽奶
 * @create 2022/8/16
 **/
@SuppressWarnings("ALL")
@Service
public class UserExamServiceImpl extends ServiceImpl<UserExamMapper, UserExam> implements IUserExamService {

    @Override
    public TableDataInfo<UserExamVo> queryUserExamList(UserExamBo bo) {
        // 直接判断当前用户是否为管理员
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            // 如果当前用户为管理员
            bo.setTeacherId(null);
        }else {
            // 如果不是管理员就设置教师id
            bo.setTeacherId(SecurityUtils.getUserId());
        }
        Page<UserExamVo> page = baseMapper.queryUserExamList(PageUtils.buildPage(bo), bo);
        return PageUtils.buildTableDataInfo(page);
    }
}
